/*
 * Homework 2
 * Group 6
 * Pham Hoang Hiep
 * Nguyen Huu Nghia
 * Nguyen Minh Tri
 * Vo Thai Ngoc
 */
package btvn;

public class Time {
	private int hour;
	private int minute;
	private int second;

	public Time() {
		this.hour = 0;
		this.minute = 0;
		this.second = 0;
	}

	public int getMinute() {
		return minute;
	}

	public int getSecond() {
		return second;
	}

	public int getHour() {
		return hour;
	}

	// Ham tuy chinh lai thoi gian hien hanh
	public void reset(int hour, int minute, int second) {
		this.hour = hour;
		this.minute = minute;
		this.second = second;
		normalize();
	}

	public String toString() {
		return this.hour + ":" + this.minute + ":" + this.second + " GMT";
	}

	// Ham chuan hoa thoi gian
	public void normalize() {
		if (this.second > 59) {
			int s = this.second%60;
			this.second = this.second - s*60;
			this.minute += s;
		}
		if (this.minute > 59) {
			int m = this.minute%60;
			this.minute = this.minute - m*60;
			this.hour += m;
		}
		if (this.hour > 23){
			int h = this.hour%24;
			this.hour = this.hour - h*24;
		}
		
		if (this.second < 0) {
			int s = Math.abs(this.second)%60;
			this.second = Math.abs(this.second) - s*60;
			this.minute -= s;
		}
		if (this.minute < 0) {
			int m = Math.abs(this.minute)%60;
			this.minute = Math.abs(this.minute) - m*60;
			this.hour -= m;
		}
		if (this.hour < 0){
			int h = Math.abs(this.hour)%24;
			this.hour = Math.abs(this.hour) - h*24;
		}		
	}

	// Ham tang thoi gian
	public void advance(int hour, int minute, int second) {
		this.hour += hour;
		this.minute += minute;
		this.second += second;
		normalize();
	}

	// Ham hien thi thoi gian
	public String print(Time time) {
		return time.toString();
	}
}
